import 'package:flutter/material.dart';

class Widget_Offstage_Page extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return Widget_Offstage_State();
  }
}

class Widget_Offstage_State extends State<Widget_Offstage_Page> {
  String showText = "hide";
  bool isOff = false;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("Offstage"),
        ),
        body: Container(
          margin: EdgeInsets.only(top: 50.0),
          child: Offstage(
            offstage: isOff,
            child: Text("Offstage组件"),
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: onButtonClickListener,
          child: Text(showText),
        ),
      ),
    );
  }

  void onButtonClickListener() {
    setState(() {
      isOff = !isOff;
    });
    if (isOff) {
      showText = "show";
    } else {
      showText = "hide";
    }
  }
}

/**
 * 控制child是否显示
 *
    当offstage为true，控件隐藏； 当offstage为false，显示；
    当Offstage不可见的时候，如果child有动画等，需要手动停掉，Offstage并不会停掉动画等操作。

    const Offstage({ Key key, this.offstage = true, Widget child })
 */
